package com.blog.service.impl;

import com.blog.dao.AxisDao;
import com.blog.dao.impl.AxisDaoImpl;
import com.blog.pojo.Article;
import com.blog.pojo.AxisVo;
import com.blog.service.AxisService;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间轴
 */
public class AxisServiceImpl implements AxisService {

    AxisDao dao= new AxisDaoImpl();
    List<AxisVo> AxisVos = new ArrayList<AxisVo>();

    @Override
    public List<AxisVo> findAxis() {
        //查找所有的年份
        List<String> allYear = dao.findAllYear();
        for (String year : allYear) {
            AxisVo axisVo1 = new AxisVo();
            axisVo1.setId(0);
            axisVo1.setYear(year);
            axisVo1.setTime(null);
            axisVo1.setTitle(null);
            AxisVos.add(axisVo1);

            //根据年份查找文章
            List<Article> allArticleByYear = dao.findAllArticleByYear(year);
            for (Article article : allArticleByYear) {
                AxisVo axisVo = new AxisVo();
                axisVo.setId(article.getId());//年份的id
                axisVo.setYear(year);
                axisVo.setTime(article.getTime());
                axisVo.setTitle(article.getTitle());
                //存到集合中
                AxisVos.add(axisVo);
            }
        }

        return AxisVos;
    }
}
